/*
 * $Id: AscUiObject.java,v 1.7 2010/01/07 21:54:51 oliver Exp $
 *
 * Copyright (C) 2006 General Electric Company. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of the General
 * Electric Company (GE). You shall not disclose this software and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with GE.
 *
 * GE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
 * NON-INFRINGEMENT. GE SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING, OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES.
 */

package com.ge.healthcare.autosc.ui.pojo;

import java.util.Date;

import com.ge.healthcare.autosc.common.ASCUtil;
import com.ge.healthcare.autosc.common.database.pojo.CfgCodeDetails;
import com.ge.healthcare.autosc.common.util.TimeFormatStandard;

public abstract class AscUiObject implements AscUiObjectI {
	private Long time;
	private String codeName;
	private Long codeId;
	private String codeGroup;
	private String codeDesc;
	/** The value of the simple startTime property. */
	private String startTime;
	/** The value of the simple endTime property. */
	private String endTime;
	private String errorMsg;
	private Boolean inError;

	public AscUiObject() {
		this.inError = false;
		this.errorMsg = "";
	}

	public void load(CfgCodeDetails codeDetails) {
		if (!ASCUtil.isNullOrEmptyObject(codeDetails)) {
			this.codeName = codeDetails.getCodeName();
			this.codeGroup = codeDetails.getCodeGroup().toString();
			this.codeDesc = codeDetails.getCodeDesc();
		}

	}

	public Long getTime() {
		return time;
	}

	/**
	 * @return the codeName
	 */
	public String getCodeName() {
		return codeName;
	}

	/**
	 * @param codeName
	 *            the codeName to set
	 */
	public void setCodeName(String codeName) {
		this.codeName = codeName;
	}

	/**
	 * @return the codeDesc
	 */
	public String getCodeDesc() {
		return codeDesc;
	}

	/**
	 * @param codeDesc
	 *            the codeDesc to set
	 */
	public void setCodeDesc(String codeDesc) {
		this.codeDesc = codeDesc;
	}

	/**
	 * Return the value of the CODE_ID column.
	 * 
	 * @return CfgCodeDetails
	 */
	public Long getCodeId() {
		return this.codeId;
	}

	/**
	 * Set the value of the CODE_ID column.
	 * 
	 * @param cfgCodeDetails
	 */
	public void setCodeId(Long codeId) {
		this.codeId = codeId;
	}

	public void setStartTime(Date startTime) {
		if (!ASCUtil.isNullOrEmptyObject(startTime)) {
			this.startTime = TimeFormatStandard
					.getDtInEndUserDisplayFormat(startTime);
			time = startTime.getTime();
		}
	}

	/**
	 * @return the startTime
	 */
	public String getStartTime() {
		return startTime;
	}

	/**
	 * @param startTime
	 *            the startTime to set
	 */
	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}

	public void setEndTime(Date endTime) {
		if (!ASCUtil.isNullOrEmptyObject(endTime)) {
			this.endTime = TimeFormatStandard
					.getDtInEndUserDisplayFormat(endTime);
		}
	}

	public void setTime(Date startTime, Date endTime) {
		if (!ASCUtil.isNullOrEmptyObject(startTime)) {
			this.startTime = TimeFormatStandard
					.getDtInEndUserDisplayFormat(startTime);
		}
		if (!ASCUtil.isNullOrEmptyObject(endTime)) {
			this.endTime = TimeFormatStandard
					.getDtInEndUserDisplayFormat(endTime);
		}
		/*
		 * This should NEVER happen start time should be set for both GEN1 and
		 * GEN2 but in case it is not I don't want to throw null pointer
		 * exceptions. This should mean that these broken requests are thrown to
		 * the top or bottom of the queue.
		 */
		if (!ASCUtil.isNullOrEmptyObject(startTime)) {
			time = startTime.getTime();
		} else if (!ASCUtil.isNullOrEmptyObject(endTime)) {
			time = endTime.getTime();
		} else {
			time = System.currentTimeMillis();
		}
	}

	/**
	 * @return the endTime
	 */
	public String getEndTime() {
		return endTime;
	}

	/**
	 * @param endTime
	 *            the endTime to set
	 */
	public void setEndTime(String endTime) {
		this.endTime = endTime;
	}

	/**
	 * @return the codeGroup
	 */
	public String getCodeGroup() {
		return codeGroup;
	}

	/**
	 * @param codeGroup
	 *            the codeGroup to set
	 */
	public void setCodeGroup(String codeGroup) {
		this.codeGroup = codeGroup;
	}

	/**
	 * @return the inError
	 */
	public Boolean getInError() {
		return inError;
	}

	/**
	 * @param inError
	 *            the inError to set
	 */
	public void setInError(Boolean inError) {
		this.inError = inError;
	}

	/**
	 * @return the errorMsg
	 */
	public String getErrorMsg() {
		return errorMsg;
	}

	/**
	 * @param errorMsg
	 *            the errorMsg to set
	 */
	public void setErrorMsg(String errorMsg) {
		this.errorMsg = errorMsg;
	}

}
